<?php

/**
 * Subclass for performing query and update operations on the 'demo_ajax' table.
 *
 * 
 *
 * @package lib.model
 */ 
class DemoAjaxPeer extends BaseDemoAjaxPeer
{
	static function getAllByRank()
	{
		$c = new Criteria;
		$c->addAscendingOrderByColumn(self::RANK);
		return self::doSelect($c);
	}

	static function doSort($order)
	{
		$con = Propel::getConnection(self::DATABASE_NAME);
		try
		{
			$con->begin();
			
			foreach ($order as $rank => $id)
			{
				$item = DemoAjaxPeer::retrieveByPk($id);
				if ($item->getRank() != $rank)
				{
					$item->setRank($rank);
					$item->save();
				}
			}
			
			$con->commit();
			return true;
		}
		catch (Exception $e)
		{
			$con->rollback();
			return false;
		}
	}

	static function getStudentsLike($student, $max = 10)
	{
		$c = new Criteria();
		$c->clearSelectColumns();
		$c->addSelectColumn(DemoAjaxPeer::NAME);
		$c->add(DemoAjaxPeer::NAME, '%'.$student.'%',Criteria::LIKE);
		$c->setLimit($max);
		
		$rs = DemoAjaxPeer::doSelectRS($c);

		while($rs->next())
		{
			$students[] = $rs->getString(1);
		}
		
		return $students;
	}
}
